package com.huang.service;

import com.huang.mapper.AttractionsMapper;
import com.huang.pojo.Attractions;
import com.huang.pojo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AttractionsServiceImpl implements AttractionsService{
@Autowired
    AttractionsMapper attractionsMapper;


    @Override
    public PageResult getAtrlist(PageResult pageResult) {
        long total=attractionsMapper.getCount(null);

        int pageNum= pageResult.getPageNum();
        int pageSize=pageResult.getPageSize();
        int startIndex = (pageNum-1) * pageSize;   //起始位置
        List<Attractions> list=attractionsMapper.getAtrList(startIndex,pageSize);

        pageResult.setTotal(total).setRows(list);
        return pageResult;

    }

    @Override
    public PageResult getAtrlist1(PageResult pageResult) {
        long total=attractionsMapper.getCount(null);

        int pageNum= pageResult.getPageNum();
        int pageSize=pageResult.getPageSize();
          String query=pageResult.getQuery();
        int startIndex = (pageNum-1) * pageSize;   //起始位置
        List<Attractions> list=attractionsMapper.getAtrList1(query,startIndex,pageSize);

        pageResult.setTotal(total).setRows(list);
        return pageResult;
    }
    //添加景点信息
    @Override
    public void addStr(String name, String atrinfo, String atrlevel, int num, int price, Boolean status) {
       attractionsMapper.addStr(null,name,atrinfo,atrlevel,num,price,status);
    }

    @Override
    public void update(int id, boolean status) {
        attractionsMapper.update(id,status);
    }

    @Override
    public void updateatr(int id, String name, String atrinfo, String atrlevel, int num, int price, Boolean status) {
        attractionsMapper.updateAtr(id,name,atrinfo,atrlevel,num,price,status);
    }

    @Override
    public void deleteStrById(Integer id) {
        attractionsMapper.deleteStrById(id);
    }

    @Override
    public List<Attractions> getAtrListl() {
    return   attractionsMapper.userGetAtrList1();
    }


}
